﻿@model HZYProject.Domain.TestPaper
@{ var list = ViewBag.Lists as List<HZYProject.Domain.Question>; }
<style type="text/css">
    h1, h2, h3, h4, h5, h6 {
        font-weight: bold;
    }

    .ptitle {
        position: relative;
        height: 100px;
        white-space: nowrap;
        border-bottom: 1px solid #e6e6e6;
        -webkit-transition: all .2s;
    }

    .layui-body {
        left: 10px;
    }

    .layui-form-item {
        margin: 0;
    }

    .layui-form-label {
        text-align: initial;
        padding: 5px 7px;
    }

    h3 {
        margin: 10px 0;
    }

    h4 {
        color: red;
        margin: 10px 0;
    }

    .choice {
        margin-left: 20px;
    }

        .choice .cfz {
            border: none;
            border-bottom: 1px solid black;
            width: 40px;
            color: red;
        }

        .choice ul {
            list-style: none;
            margin: 0;
            padding: 0;
            margin-top: 10px;
        }

            .choice ul li {
                margin-left: 25px;
                line-height: 25px;
            }


    p:first-child {
        display: inline-block;
    }
</style>
<div class="ptitle">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-col-xs6">
                <input type="hidden" name="TestPaperID" id="TestPaperID" value="@Model.TestPaperID" />
                <div class="layui-form-item">
                    <label class="layui-form-label"><b>试卷标题:</b></label>
                    <label class="layui-form-label"><b style="color:red;">@Model.Title</b></label>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><b>总分:</b></label>
                    <label class="layui-form-label"><b style="color:red;" id="totalScore">100</b>分</label>
                </div>
            </div>
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label"><b>试题:</b></label>
                    <label class="layui-form-label"><b style="color:red;">@Model.QCount</b></label>
                </div>
                <div class="layui-form-item">
                    <button type="button" class="layui-btn layui-btn-normal" data-type="addChoice">添加客观题</button>
                    <button type="button" class="layui-btn layui-btn-danger" data-type="del">删除试题</button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="layui-body layui-form">
    <h3>第一部分：客观题</h3>
    <div id="paperChoices">
        @{
                <div class="course">
                    <h4>
                        <input type="checkbox" name="cquanxuan" lay-skin="primary" title="全选" lay-filter="choiceCekAll">
                        课程：@Model.CourseID (预设数量：@Model.QCount,实际数量：25)
                    </h4>
                    @if (list != null)
                    {
                        foreach (var item in list)
                        {
                            <div class="choice" id="div_67860">
                                <h5>
                                    <input type="checkbox" name="ctimu" lay-skin="primary" value="67860">
                                    <span>
                                        1、@item.Title

                                    </span>
                                    <span style="color:blue">答案：C（分数：<input type="number" id="67860" class="cfz" value="2" />）</span>
                                </h5>
                                <ul>
                                    <li>A：0,1,2,3,4</li>
                                    <li>B：1,2,3,4</li>
                                    <li>C：1,2,3,4,5</li>
                                    <li>D：0,1,2,3,4,5</li>
                                </ul>
                            </div>
                        }
                    }
                </div>
        }

        @*<div class="course">
            <h4>
                <input type="checkbox" name="cquanxuan" lay-skin="primary" title="全选" lay-filter="choiceCekAll">

                课程：Asp.net MVC高级开发（预设数量：25,实际数量：25）
            </h4>
            <div class="choice" id="div_67885">
                <h5>
                    <input type="checkbox" name="ctimu" lay-skin="primary" value="67885">
                    <span>
                        1、<span class="red">【完全公开】</span>
                        <p>关于下图中的代码以下说法错误的是？</p><p><img src="http://static.ysdjypt.com//StaticResources/UEditImages/3048695b0527437b96a40f931ea6c6cb.jpg" title="3048695b0527437b96a40f931ea6c6cb.jpg" alt="3048695b0527437b96a40f931ea6c6cb.jpg" /></p>
                    </span>
                    <span style="color:blue">答案：D（分数：<input type="number" id="67885" class="cfz" value="2" />）</span>
                </h5>
                <ul>
                    <li>A：form表单中的action属性值是上传文件时调用的接口</li>
                    <li>B：form表单中的method属性值是请求的类型</li>
                    <li>C：&lt;input type=&quot;file&quot; name=&quot;up&quot; /&gt; 这个input的作用就是向服务端发送文件</li>
                    <li>D：&lt;input type=&quot;file&quot; name=&quot;up&quot; /&gt; 这个input的作用是只能上传图片文件</li>
                </ul>
            </div>
        </div>
        <div class="course">
            <h4>
                <input type="checkbox" name="cquanxuan" lay-skin="primary" title="全选" lay-filter="choiceCekAll">
                其它课程（预设数量：0,实际数量：0）
            </h4>
        </div>*@
    </div>
    <input type="hidden" id="focusFZ" />
</div>

@section script{
    <script>

        layui.use(['form', 'jquery'], function () {
            var form = layui.form;
            let $ = layui.jquery;

            var testPaperId = $("#TestPaperID").val();
            var active = {
                addChoice: function () {
                    var ins = layer.open({
                        type: 2
                        , title: '试题列表'
                        , area: ["500px", "400px"]
                        , offset: 'auto'
                        , shade: 0.5
                        , maxmin: true
                        , anim: 1
                        , content: '/TestPaper/searchQuestion?id=' + testPaperId
                        //, content: '/TestPaper/PaperChoiceList?id=456'
                        //, id: 'paperChoiceList'
                    });
                    layer.full(ins);
                }
                , del: function () {
                    var cekCIdStr = '';
                    $('[name=ctimu]').each(function (index, ele) {
                        if ($(this).is(':checked')) {
                            if (cekCIdStr == '') {
                                cekCIdStr = $(this).val();
                            }
                            else {
                                cekCIdStr += ',' + $(this).val();
                            }
                        }
                    });

                    if (cekCIdStr == '') {
                        layer.msg('请选择要删除的题目', { icon: 5 });
                        return;
                    }
                    layer.confirm('您确定要删除吗？如果是则会删除所有题目', function (index) {
                        $.ajax({
                            url: '/TestPaper/deleteQuestions',
                            type: 'Post',
                            data: {
                                'id': testPaperId
                            },
                            dataType: 'json',
                            success: function (result) {
                                if (result.Error) {
                                    layer.msg(result.Msg, { icon: 2 });
                                    return;
                                }
                                layer.alert('删除成功！（试题：【' + result.count + '】道）', { icon: 1 }, function () {
                                    window.location.reload();
                                });
                            },
                            error: function () {
                                layer.msg('抱歉，服务器繁忙，请稍后再试！', { icon: 5 });
                            }
                        });
                    });
                }
            };

            $('.layui-form .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            form.on('checkbox(choiceCekAll)', function (data) {
                if (data.elem.checked) {
                    $(data.elem).parents('.course').find('[name=ctimu]').each(function () {
                        $(this).prop('checked', true);
                    });
                }
                else {
                    $(data.elem).parents('.course').find('[name=ctimu]').each(function () {
                        $(this).prop('checked', false);
                    });
                }
                form.render('checkbox');
            });

        });

            //$('.cfz').on('focus', function () {
            //    $('#focusFZ').val($(this).val());
            //})

            //$('.cfz').on('blur', function () {
            //    var oldFz = $('#focusFZ').val();
            //    var s = $(this);
            //    if (s.val() * 1 != 1 && s.val() * 1 != 2 && s.val() * 1 != 3) {
            //        layer.msg('客观题分值必须是（1、2、3）', { icon: 5 });
            //        s.val(oldFz);
            //        return;
            //    }

            //    $.ajax({
            //        url: '/Home/ChangePaperChoiceScore',
            //        type: 'Post',
            //        data: {
            //            'pId': 456,
            //            'id': s.attr('id'),
            //            'score': s.val()
            //        },
            //        dataType: 'json',
            //        success: function (result) {
            //            if (result.Error) {
            //                s.val(oldFz);
            //                layer.msg(result.Msg, { icon: 2 });
            //                return;
            //            }
            //            layer.msg('修改分值成功', { icon: 1 });
            //            var totalScore = $('#totalScore');
            //            var tScore = 0;
            //            $('.cfz').each(function () {
            //                tScore += $(this).val() * 1;
            //            });
            //            totalScore.text(tScore);//totalScore.text() * 1 - oldFz * 1 + s.val() * 1
            //        },
            //        error: function () {
            //            s.val(oldFz);
            //            layer.msg('抱歉，服务器繁忙，请稍后再试！', { icon: 5 });
            //        }
            //    });
            //})

    </script>
}